<%--
  Created by IntelliJ IDEA.
  User: asus
  Date: 2017/6/20
  Time: 8:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>
    <!-- 引入JQuery -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.min.js"></script>
    <!-- 引入EasyUI -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
    <!-- 引入EasyUI的中文国际化js，让EasyUI支持中文 -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/easyui-lang-zh_CN.js"></script>
    <!--
    <script  type="text/javascript" src="scripts/index.js"></script>
  -->
    <!-- 引入EasyUI的样式文件-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css" type="text/css"/>
    <!-- 引入EasyUI的图标样式文件-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/easyui/themes/icon.css" type="text/css"/>

</head>
<body>
<table id="group_list_dg" style="width:auto" >
    <thead>
    <tr>
        <th data-options="field:'id'">用户编号</th>
        <th data-options="field:'name'">用户名</th>
        <th data-options="field:'roleName'">用户角色</th>
        <th data-options="field:'flag'">是否有权限修改</th>
    </tr>
    <thead>
</table>

<div id="group_save_dialog" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
     closed="true" buttons="#group_save_dialog_buttons" modal="true">
    <div class="ftitle">请输入机构信息</div>
    <form id="group_info_form" method="post">
        <div class="fitem">
            <label>名称:</label>
            <input type="text" name="name" />
        </div>
        <div class="fitem">
            <label>类型:</label>
            <input type="text" name="type" />
        </div>
        <div class="fitem">
            <label>库存量:</label>
            <input type="text" name="quantity" />
        </div>
        <div class="fitem">
            <label>价格:</label>
            <input type="text" name="price" />
        </div>

        <input type="hidden" name="id" />
    </form>
</div>
<div id="group_save_dialog_buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveGroup()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#group_save_dialog').dialog('close')">取消</a>
</div>

<script type="text/javascript">
    var UrlConfig = {
        SysGroupList: '<%=request.getContextPath() %>/user/list',
        SysGroupDwon: '<%=request.getContextPath() %>/user/down',
        SysGroupUpper: '<%=request.getContextPath() %>/user/upper',
    };
    $(function(){
        $('#group_list_dg').datagrid({
            url: UrlConfig.SysGroupList,
            toolbar: '#group_list_dg_toolbar',
            striped: true ,					//隔行变色特性
            loadMsg: '数据正在加载,请耐心的等待...' ,
            singleSelect: true,
            rownumbers: true,
            fit: true,
            fitColumns: true,
            pagination: true ,
            pageSize: 10 ,
            pageList:[5,10,15,20,50],
            toolbar:[
                {
                    text:'将普通雇员设置为仓库经理',
                    iconCls:'icon-add',
                    handler:updateToUpper
                },

                {
                    text:'将仓库经理设置为普通雇员',
                    iconCls:'icon-remove',
                    handler:updateToLower
                }
            ]
        });
    });
    var url;
    function updateToLower(){
        var row = $('#group_list_dg').datagrid('getSelected');
        if (row) {
           if(row.flag==false){
               $.messager.alert("警告","您没有权限对该用户进行修改，操作失败",'warning');
           }else{
               $.post(UrlConfig.SysGroupDwon, {id:row.id,name:row.name}, function(result){
                   console.log(result);
                   if(result.status=="200"){
                       $.messager.show({ title: '操作结果', msg: '操作成功' });
                       $('#group_list_dg').datagrid('reload');
                   }else{
                       $.messager.show({ title: '操作结果', msg: result.message });
                   }
               },'json');
           }
        }

    }
    function updateToUpper(){
        var row = $('#group_list_dg').datagrid('getSelected');
        if (row) {
            if(row.flag==false){
                $.messager.alert("警告","您没有权限对该用户进行修改，操作失败",'warning');
            }else{
                $.post(UrlConfig.SysGroupUpper, {id:row.id,name:row.name}, function(result){
                    console.log(result);
                    if(result.status=="200"){
                        $.messager.show({ title: '操作结果', msg: '操作成功' });
                        $('#group_list_dg').datagrid('reload');
                    }else{
                        $.messager.show({ title: '操作结果', msg: result.message });
                    }
                },'json');
            }
        }

    }
</script>
</body>
</html>
